package com.hp.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.hp.ssm.entity.Cases;
import com.hp.ssm.service.CaseService;
import com.hp.ssm.util.GeneratID;
import com.hp.ssm.util.ResultJson;
import com.hp.ssm.util.TimeUtils;
import com.hp.ssm.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/article")
public class CaseController {
    @Autowired
    private CaseService caseService;

    /*
    * 基因检测项目*/
    @RequestMapping("/findAll")
    @ResponseBody
    public void findAll(Cases cases,Integer page, Integer limit,HttpServletResponse resp){
        System.out.println(cases + "你好我是page and  limit  " + limit+"eqweq"+ cases);
        List<Cases> list = caseService.findAll(cases, page, limit);
        PageInfo<Cases> userPageInfo = new PageInfo<Cases>(list);
        System.out.println(list);
        System.out.println(list.size());
            Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
    @RequestMapping("/add")
    @ResponseBody
    public void add(Cases cases,HttpServletResponse resp){
        Date ctime = new Date();
        cases.setCtime(ctime);
        String cidnum = GeneratID.getGeneratID();
        cases.setCidnum(cidnum);
        int i = caseService.add(cases);
        Utils.returnJson(ResultJson.success(i), resp);
    }
    @RequestMapping("/findById")
    @ResponseBody
    public void findById(Cases cases,HttpServletResponse resp){
        Cases cases1 = caseService.findById(cases);
        Utils.returnJson(ResultJson.success(cases1), resp);
    }
    @RequestMapping("/update")
    @ResponseBody
    public void update(HttpServletResponse resp,Cases cases){
        int i = caseService.update(cases);
        Utils.returnJson(ResultJson.success(i), resp);
    }
    @RequestMapping("/delete")
    @ResponseBody
    public void delete(Cases cases,HttpServletResponse resp){
        int i = caseService.delete(cases);
        Utils.returnJson(ResultJson.success(i), resp);
    }
    @RequestMapping("/delfindAll")
    @ResponseBody
    public void delfindAll(Cases cases,Integer page, Integer limit,HttpServletResponse resp){
        System.out.println(page + "你好我是page and  limit  " + limit+"eqweq"+ cases);
        List<Cases> list = caseService.delfindAll(cases, page, limit);
        PageInfo<Cases> userPageInfo = new PageInfo<Cases>(list);
        System.out.println(list);
        System.out.println(list.size());
        Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
    @RequestMapping("/recover")
    @ResponseBody
    public void recover(Cases cases,HttpServletResponse resp){
        int i = caseService.recover(cases);
        Utils.returnJson(ResultJson.success(i), resp);
    }
    @RequestMapping("/findAll2")
    @ResponseBody
    public void findAll2(Cases cases,Integer page, Integer limit,HttpServletResponse resp){
        System.out.println(cases + "你好我是page and  limit  " + limit+"eqweq"+ cases);
        List<Cases> list = caseService.findAll2(cases, page, limit);
        PageInfo<Cases> userPageInfo = new PageInfo<Cases>(list);
        System.out.println(list);
        System.out.println(list.size());
        Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
    @RequestMapping("/add2")
    @ResponseBody
    public void add2(HttpServletResponse resp,Cases cases){
        Date ctime = new Date();
        cases.setCtime(ctime);
        String cidnum = GeneratID.getGeneratID();
        cases.setCidnum(cidnum);
        int i = caseService.add2(cases);
        Utils.returnJson(ResultJson.success(i), resp);
    }
    @RequestMapping("/update2")
    @ResponseBody
    public void update2(HttpServletResponse resp,Cases cases){
        int i = caseService.update2(cases);
        Utils.returnJson(ResultJson.success(i), resp);
    }
    @RequestMapping("/delfindAll2")
    @ResponseBody
    public void delfindAll2(Cases cases,Integer page, Integer limit,HttpServletResponse resp){
        System.out.println(page + "你好我是page and  limit  " + limit+"eqweq"+ cases);
        List<Cases> list = caseService.delfindAll2(cases, page, limit);
        PageInfo<Cases> userPageInfo = new PageInfo<Cases>(list);
        System.out.println(list);
        System.out.println(list.size());
        Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
    @RequestMapping("/findAll3")
    @ResponseBody
    public void findAll3(Cases cases,Integer page, Integer limit,HttpServletResponse resp){
        System.out.println(cases + "你好我是page and  limit  " + limit+"eqweq"+ cases);
        List<Cases> list = caseService.findAll3(cases, page, limit);
        PageInfo<Cases> userPageInfo = new PageInfo<Cases>(list);
        System.out.println(list);
        System.out.println(list.size());
        Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
    @RequestMapping("/add3")
    @ResponseBody
    public void add3(HttpServletResponse resp,Cases cases){
        Date ctime = new Date();
        cases.setCtime(ctime);
        String cidnum = GeneratID.getGeneratID();
        cases.setCidnum(cidnum);
        int i = caseService.add3(cases);
        Utils.returnJson(ResultJson.success(i), resp);
    }
    @RequestMapping("/deletefindAll3")
    @ResponseBody
    public void deletefindAll3(Cases cases,Integer page, Integer limit,HttpServletResponse resp){
        System.out.println(page + "你好我是page and  limit  " + limit+"eqweq"+ cases);
        List<Cases> list = caseService.deletefindAll3(cases, page, limit);
        PageInfo<Cases> userPageInfo = new PageInfo<Cases>(list);
        System.out.println(list);
        System.out.println(list.size());
        Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
}